package com.laviedesfons.jhmtasc.logging;

import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;

/**
 *
 * @author Romano
 */
public class CustomLogger {

    public static final String DEFAULT_LOGGER_NAME = "JHMTASC";

    private static final Logger logger = Logger.getLogger(DEFAULT_LOGGER_NAME);

    private static final ConsoleHandler handler = new ConsoleHandler();

    private static CustomLogger instance = null;

    private static Level defaultLevel = CustomLevel.TEST;

    public static void setLevel(Level lvl){
        logger.setLevel(lvl);
        handler.setLevel(lvl);
    }

    private CustomLogger(){
        logger.setUseParentHandlers(false);
        CustomFormatter formatter = new CustomFormatter();
        handler.setFormatter(formatter);
        handler.setLevel(defaultLevel);
        logger.setLevel(defaultLevel);
        logger.addHandler(handler);
        LogManager.getLogManager().addLogger(logger);
    }

    public static Logger getLogger(){
        if(instance == null){
            instance = new CustomLogger();
        }
        return logger;
    }
}